package com.yanggu.scala.chapater11.exercise

//大数据经典的WordCount案例
object Exercise04 {

  def main(args: Array[String]): Unit = {
    //val lines = List("atguigu han hello ", "atguigu han aaa aaa aaa ccc ddd uuu")
    //使用映射集合，list中，各个单词出现的次数，并按出现次数排序
    val lines = List("atguigu han hello ", "atguigu han aaa aaa aaa ccc ddd uuu")
    val tuples = lines
      .flatMap(_.split(" "))
      .map((_, 1))
      .groupBy(_._1)
      .map(tuple => (tuple._1, tuple._2.size))
      .toList
      .sortBy(tuple => (-tuple._2, tuple._1))
    println(tuples)

  }

}
